package view.renderer;

import java.awt.Color;
import java.awt.Graphics;

public class FPSRenderer extends Renderer{
	
	private int lastFPS;
	private int frameCounter;
	private long secondStart;
	
	//Konstanten
	public static int X_POSITION = 950;
	public static int Y_POSITION = 20;
	public static Color COLOR = new Color(250, 250, 250);

	public FPSRenderer(){
		frameCounter = 0;
		lastFPS = 0;
		secondStart = System.currentTimeMillis();
	}
	
	private void updateFPS(){
		if((System.currentTimeMillis() - secondStart) > 1000){
			lastFPS = frameCounter;
			frameCounter = 0;
			secondStart = System.currentTimeMillis();
		}
		else{
			frameCounter++;
		}
	}
	
	@Override
	public void render(Graphics g) {
		updateFPS();
		String frames = "FPS: " + lastFPS;
		g.setColor(COLOR);
		g.drawChars(frames.toCharArray(), 0, frames.length(), X_POSITION, Y_POSITION);
	}

}
